package com.zucai365.football.service.impl;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.wcj.common.service.impl.WcjServiceImpl;
import com.zucai365.football.bean.LianSaiInfoBean;
import com.zucai365.football.dao.LianSaiInfoDao;
import com.zucai365.football.service.LianSaiInfoService;

@Service("lianSaiInfoService")
public class LianSaiInfoServiceImpl extends WcjServiceImpl<LianSaiInfoBean> implements LianSaiInfoService{
	
	@Autowired
	@Qualifier("lianSaiInfoDao")
	private LianSaiInfoDao lianSaiInfoDao;

	public LianSaiInfoDao getLianSaiInfoDao() {
		return lianSaiInfoDao;
	}

	public void setLianSaiInfoDao( LianSaiInfoDao lianSaiInfoDao ) {
		this.lianSaiInfoDao = lianSaiInfoDao;
	}

	@Override
	public List<LianSaiInfoBean> getLianSaiInfo( Long lianSaiId,
			Long lianSaiYearId) {
		
		DetachedCriteria criteria = DetachedCriteria.forClass( LianSaiInfoBean.class, "lianSaiInfo" );
		criteria.createAlias( "lianSaiInfo.lianSaiYear", "lianSaiYear" );
		criteria.createAlias( "lianSaiInfo.lianSai", "lianSai" );
		
		if( lianSaiId != null ){
			criteria.add( Restrictions.eq( "lianSai.id" , lianSaiId ) );
		}
		
		if( lianSaiYearId != null ){
			criteria.add( Restrictions.eq( "lianSaiYear.id" , lianSaiYearId ) );
		}
		
		criteria.addOrder( Order.asc( "lianSai.viewOrder" ) );
		
		return this.lianSaiInfoDao.findByCriteria(criteria);
	}
	
}
